package ink.onei.production.interceptor;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author: dang
 * @Description: 登录拦截器
 * @Date: 2023/12/20 19:02 星期三
 */
public class AuthInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String username = (String) request.getSession().getAttribute("loginUser");
        if (username == null) {
            response.sendRedirect("/system/login");
            return false;
        } else {
            return super.preHandle(request, response, handler);
        }
    }

}

